home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / disabl1r / sinewave.bas < prev    next >
Encoding:
BASIC Source File  |  1999-03-30  |  3.1 KB  |  124 lines

  1. Attribute VB_Name = "mdSineWave"
  2. Option Explicit
  3.  
  4. Global Const pi = 3.14159265358979
  5.  
  6. Public Type OrderedPair
  7.     X As Currency
  8.     Y As Currency
  9. End Type
  10.  
  11. Global Const WV_SIN = 0
  12. Global Const WV_COS = 1
  13. Global Const WV_TAN = 2
  14. Global Const WV_SEC = 3
  15. Global Const WV_CSC = 4
  16. Global Const WV_COT = 5
  17. Global Const WV_0 = "SIN"
  18. Global Const WV_1 = "COS"
  19. Global Const WV_2 = "TAN"
  20. Global Const WV_3 = "SEC"
  21. Global Const WV_4 = "CSC"
  22. Global Const WV_5 = "COT"
  23.  
  24. Public CenterPoint As OrderedPair
  25. Public Squares As OrderedPair
  26. Public PixelUnit As Integer
  27. Public UnitMode As Long
  28.  
  29. Public WvHigh As Currency
  30. Public WvWide As Currency
  31. Public WvXPos As Currency
  32. Public WvYPos As Currency
  33. Public WvXMult As Currency
  34. Public WvType As Integer
  35.  
  36. Public Function Cosine(ByVal i As Double) As Double
  37.     Cosine = Cos(i * (pi / 180))
  38. End Function
  39.  
  40. Public Function Sine(ByVal i As Double) As Double
  41.     Sine = Sin(i * (pi / 180))
  42. End Function
  43.  
  44. Public Function Tangent(ByVal i As Double) As Double
  45.     Tangent = Tan(i * (pi / 180))
  46. End Function
  47.  
  48. Public Function Secant(ByVal i As Double) As Double
  49.     Secant = 1 / Cosine(i)
  50. End Function
  51.  
  52. Public Function Cosecant(ByVal i As Double) As Double
  53.     Cosecant = 1 / Sine(i)
  54. End Function
  55.  
  56. Public Function Cotangent(ByVal i As Double) As Double
  57.     Cotangent = 1 / Tangent(i)
  58. End Function
  59.  
  60. Public Function Wave(ByVal i As Double) As Double
  61.     Select Case WvType Mod 6
  62.         Case WV_SIN
  63.             Wave = Sine(i)
  64.         Case WV_COS
  65.             Wave = Cosine(i)
  66.         Case WV_TAN
  67.             Wave = Tangent(i)
  68.         Case WV_SEC
  69.             Wave = Secant(i)
  70.         Case WV_CSC
  71.             Wave = Cosecant(i)
  72.         Case WV_COT
  73.             Wave = Cotangent(i)
  74.     End Select
  75. End Function
  76.  
  77. Public Function WaveName() As String
  78.     WvType = WvType Mod 6
  79.     If WvType = 0 Then WaveName = WV_0
  80.     If WvType = 1 Then WaveName = WV_1
  81.     If WvType = 2 Then WaveName = WV_2
  82.     If WvType = 3 Then WaveName = WV_3
  83.     If WvType = 4 Then WaveName = WV_4
  84.     If WvType = 5 Then WaveName = WV_5
  85. End Function
  86.  
  87. Function GetType(Wave As String) As Integer
  88.     If Trim(UCase(Wave)) = WV_0 Then
  89.         GetType = 0
  90.     ElseIf Trim(UCase(Wave)) = WV_1 Then
  91.         GetType = 1
  92.     ElseIf Trim(UCase(Wave)) = WV_2 Then
  93.         GetType = 2
  94.     ElseIf Trim(UCase(Wave)) = WV_3 Then
  95.         GetType = 3
  96.     ElseIf Trim(UCase(Wave)) = WV_4 Then
  97.         GetType = 4
  98.     ElseIf Trim(UCase(Wave)) = WV_5 Then
  99.         GetType = 5
  100.     Else
  101.         GetType = 0
  102.     End If
  103. End Function
  104.  
  105. Public Function GetGraphPos(Point As OrderedPair) As OrderedPair
  106.     GetGraphPos.X = Point.X + CenterPoint.X
  107.     GetGraphPos.Y = Point.Y + CenterPoint.Y
  108. End Function
  109.  
  110. Public Function GetWaveY(X As Currency) As Currency
  111.     GetWaveY = (Wave(X) * PixelUnit * -WvHigh)
  112. End Function
  113.  
  114. Function Distance(Point1 As OrderedPair, Point2 As OrderedPair) As Currency
  115. Dim X As Currency, Y As Currency
  116.     X = (Point1.X - Point2.X) ^ 2
  117.     Y = (Point1.Y - Point2.Y) ^ 2
  118.     Distance = Sqr(X + Y)
  119. End Function
  120.  
  121. Function GetSign(Number As Currency) As Integer
  122.     GetSign = Number / Abs(Number)
  123. End Function
  124.